<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/pages/login/common.jsp" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta content="B2B电商平台" name="description"/>
<meta content="B2B电商平台" name="keyword"/>

<title>B2B电商平台.邮箱认证</title>
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/style.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/register_icss.css" />
<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/mmt_trading.css" />
<script type="text/javascript" src="<%=path %>/include/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="<%=path %>/include/js/icss.common.js"></script>
<style type="text/css">
body{margin:0;padding-left:5px;}
</style>
<script type="text/javascript">
	var oldEmailAddress="${emailAddress }";
	$(document).ready(function() {
		_findPinNum();
		$("#emailAddress").live("change", function() {
			if(checkEmailAddress($(this).val())){
				$("#error_pwd_tip").hide();
			} else {
				$("#error_pwd_tip").show();
			}
		});
	});
//换一张
function _refresh(){
	var obj=$("#pinpic");
 	obj.attr("src","<%=path %>/verifyCode/refresh.do?widthP=74&heightP=36&t="+Math.random());
}
//下一步
function _sendEmail(opeFlag){
	var flag=_checkVal();
	if(flag){
		parent._showLoading();
		var emailAddress=$("#emailAddress").val();
		if(oldEmailAddress==emailAddress){
			parent.swal('请输入新邮箱地址！'); 
			return false;
		}
//		emailAddress = emailAddress.replace("@",".E40.");
		var userCode=$("#userCode").val();
		var url = '<%=path%>/emailAuthenticate/sendEmailAuthenticate.do';
		$.ajax({
	         cache: true,
	         type: "POST",
	         url: url,
	         async: false,
	         dataType:"json",
	         data:{emailAddress:emailAddress,userCode:userCode,opeFlag:opeFlag},
	         error: function(request) {
	           parent.swal('操作失败，请稍候重试!'); 
	           parent._hideLoading(); 
	         },
	        success:function(data){
				parent._hideLoading();
				if(data.success){
					if(data.msg=="COMPLETED"){
						parent.swal("您已认证邮箱！");
						document.location.href="<%=path%>/emailAuthenticate/emailAuthenticateResult.do?userCode="+userCode;
					} else {
						_tip(userCode);
					}
				} else {
					parent.swal(data.msg);
				}
			}
	    });
	}
}
function _tip(userCode){
	parent.swal({
		title: "认证提示", 
		text: "您是否已完成邮箱认证？", 
		type: "warning",
		showCancelButton: true,
		closeOnConfirm: false,
		cancelButtonText: "取消",
		confirmButtonText: "已完成",
		confirmButtonColor: "#ec6c62"
		}, function() {
			parent.swal.close();
			document.location.href="<%=path%>/emailAuthenticate/emailAuthenticateResult.do?userCode="+userCode;
		});
}
function _checkVal(){
	var result = false;

	//验证码输入是否正确
	_findPinNum();
	var pinNum=$("#pinNum").val();
	var pin=$("#pin").val();
	if(pin.toLowerCase() != pinNum.toLowerCase() ){
		$("#error_pin_tip_tr").show();
		result = false;
	}else{
		$("#error_pin_tip_tr").hide();
		result = true;
	}
	if(!result){
		_refresh();
		return false;
	}
	//密码输入是否正确
	var emailAddress=$("#emailAddress").val();
	var userCode=$("#userCode").val();
	
	return result;
}



//查询验证码数值
function _findPinNum(){
	 $.ajax({
             cache: true,
             type: "POST",
             url: '<%=path%>/verifyCode/findPinNum.do',
             async: false,
             dataType:"json",
             error: function(request) {
               alert('操作失败，请稍候重试!');  
             },
            success:function(data){
				if(data.success){
					var pinValue=data.obj;
					$("#pinNum").val(pinValue);
				}
			}
        });
}
</script>
</head>
 <body style="font-family: '微软雅黑';padding: 0px;">
	<div id="contentDiv" style="padding:5px; width:99%;margin: 0px;">
 	<div style="width:100%;height:30px;border-bottom:1px solid #ADADAD">
 		<div class="toptil">邮箱认证</div>
 	</div>
 	
	<div class="secr_flowsteps">
		<ol class="secr_step3">
		<li class="current" style="width:49.995%;"><span class="first">1.邮箱认证</span></li>
		<li class="next" style="width:49.995%;"><span>2.认证结果</span></li>
		</ol>
	</div>	
	<div id="divForm"  class="formTable" style="margin-left:5px;padding:5px;width:98%;">
		<form id="form1" name="form1" method="post" style="margin:0px;">
		<input type="hidden" id="userCode" name="userCode" value="${userCode }" />
		<input type="hidden" id="pinNum" name="pinNum"  />
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
    		<c:if test="${emailAddress ne ''}">
        	<tr>
				<td style="width:15%;padding-left:20px;text-align:right;font-size:14px;">已认证邮箱：</td>
                <td style="width:85%;height:30px;padding-top:20px;">${emailAddress }</td>
            </tr>
    		</c:if>
        	<tr>
				<td style="width:15%;padding-left:20px;text-align:right;font-size:14px;">认证邮箱：</td>
                <td style="width:85%;height:50px;padding-top:20px;">
                	<input id="emailAddress" name="emailAddress" type="text" nowrap style="width: 150px;height:30px;" value="${emailAddress }" />
                	<div class="entry-hint" style="padding-top:0px;margin-top:0px;">
               		 <div id="error_pwd_tip" class="icon-c" style="display:none;font-size:14px;color:red;"><p></p><span>认证邮箱不符合规则！</span></div>
               		</div>
                </td>
            </tr>
            <tr>
				<td  style="width:15%;padding-left:20px;text-align:right;font-size:14px;">验证码：</td>
                <td  style="width:85%;height:50px;padding-top:4px;" >
                	<div style="height:50px;line-height:50px;over-flow:hidden;">
	                	<div style="width:155px;height:50px;padding-top:10px;line-height:50px;vertical-align: baseline;float:left;">
	                		<input id="pin" name="pin" type="text" style="width: 150px;height:30px;" />
	                	</div>
	                	<div style="width:80px;height:50px;padding-top:10px;line-height:50px;vertical-align: baseline;float:left;">
	                		<img id="pinpic" src = "<%=path %>/verifyCode/refresh.do?widthP=70&heightP=30" style="width:70px;height:30px;" onclick="_refresh();"/>
	                	</div>
	                	<a href="javascript:void('')" onclick="_refresh();" target="_self" ><span style="font-size:14px;">换一张</span></a>
                	</div>
                </td>
            </tr>
            <tr style="display:none;" id="error_pin_tip_tr">
				<td  style="width:15%;padding-left:20px;text-align:right;font-size:14px;"></td>
                <td  style="width:85%;height:30px;" >
                	<div class="entry-hint" style="padding-top:0px;margin-top:0px;">
						<div id="error_pin_tip" class="icon-c" style="font-size:14px;color:red;"><p></p><span>验证码输入不匹配！</span></div>
                	</div>
                </td>
            </tr>
            <tr>
            	<td  style="width:15%;padding-left:20px;"></td>
                <td   style="width:85%;" align="left" >
                	<c:if test="${emailAddress ne ''}">
					<input type="button" style="border:none;background-position:3px -286px" class="btn_base" style="" value="更换邮箱" onclick="_sendEmail('update')"/>
                	</c:if>
                	<c:if test="${emailAddress eq ''}">
					<input type="button" style="border:none;background-position:3px -286px" class="btn_base" style="" value="发送邮件" onclick="_sendEmail('')"/>
                	</c:if>
                </td>
            </tr>
            <tr style="height:30px;"></tr>
            <tr style="height:30px;"></tr>
            <tr>
            	<td colspan="2"  style="width:85%;height:30px;font-size:14px;text-align:left;" ><span>请确保认证邮箱地址正确，发送验证邮件后请进入邮箱接收邮件并按提示操作</span></td>
            </tr> 
           
        </table>
        </form>
    </div> 
	
 	</div>
 </body>
 <script type="text/javascript">
 $(document).ready(function(){
		_reHeight("rightFrame","contentDiv");
 });

  </script>
</html>
